<!--<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Send Email</title>
    </head>
    <body>
         Creating the form, so the user could be able to retry sending an Email
      <form action="SendEmailForm.php" method="POST" name="SendEmail" enctype="multipart/form-data">
<p> 
    <input name="GoBack" type="submit" value="Go Back">
</p>
</form>
    </body>
</html>-->
<?php
// Staring a session and mysql connection
Session_start();
$id = $_SESSION['member_id'];
$confid = $_POST['confid'];
$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db("mydb", $conn) or die(mysql_error());

// Identifying the logged-in user and collecting some information about him 
$query = mysql_query("SELECT * FROM member WHERE member_id ='$id'");
$row = mysql_fetch_array($query);

$firstname = $row['first_name'];
$lastname = $row['last_name'];
$email = $row['email'];
$text = $_POST['textarea'];
$message = $_POST['textarea'];
$subject = $_POST['subject'];

// Identifying the reciever's email 
$query = mysql_query("SELECT * FROM conference WHERE conference_id ='$confid'");
$row = mysql_fetch_array($query);

$recieverid = $row['creator_id'];

$query = mysql_query("SELECT * FROM member WHERE member_id ='$recieverid'");
$row = mysql_fetch_array($query);

$to = $row['email'];



// Creating the Email Template
$message = <<<EMAIL
Hello my name is $firstname $lastname
$text

Yours $firstname $lastname
Email : $email

EMAIL;

// Creating Error Template
$error = <<<ERROR
Email Sending Failed, it could for one of the following reasons: <br>
1- There was no subject. <br>
2- The message was empty. <br>

ERROR;

$from = "From: $email";

// Checking for the validity of the message
$mail = mail($to, $subject, $message, $from);
if (!$mail || $subject == '' || $text == '') {
    echo "$error";
} else {
    echo "Your Email has been sent succesfully.";
}
mysql_close($conn);
?>